//
//  DYAddPermissionCell.m
//  kafuMerchant
//
//  Created by 帝云科技 on 2018/9/19.
//  Copyright © 2018年 帝云科技. All rights reserved.
//

#import "DYAddPermissionCell.h"

@interface DYAddPermissionCell ()

@property (nonatomic,strong)UIButton *permissionButton;

@end


@implementation DYAddPermissionCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(void)dy_initUI
{
    [super dy_initUI];
    
    self.sideMargin=BILIWIDTH(10);
    [self xhq_noneSelectionStyle];
    
    self.permissionButton = ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:ClearColor action:@selector(buttonClick:) target:self title:@"商铺信息" image:@"icon_choose_n" font:12 textColor:[UIColor xhq_aTitle]];
        [button setImage:IMG(@"icon_choose_s") forState:UIControlStateSelected];
        [button placeImageTitlePosition:ZYButtonImagePositionLeft space:BILIWIDTH(5)];
         button.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
        button;
    });
    
    [self addSubview:self.permissionButton];
    
    
    [self.permissionButton makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(BILIWIDTH(12));
        make.top.equalTo(BILIHEIGHT(1));
        make.height.equalTo(BILIHEIGHT(35));
    }];
    
    NSArray *array=@[@"基本信息",@"我要装修",@"我要收款",@"我要发卡",@"我要认证"];
    for (NSInteger i=0; i<5; i++) {
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:ClearColor action:@selector(buttonClick:) target:self title:array[i] image:@"icon_choose_n" font:12 textColor:[UIColor xhq_aTitle]];
        button.tag=100+i;
         [button setImage:IMG(@"icon_choose_s") forState:UIControlStateSelected];
        button.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
        [button placeImageTitlePosition:ZYButtonImagePositionLeft space:BILIWIDTH(5)];
        [self addSubview:button];
        
        [button makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.permissionButton.right).offset(i%3*BILIWIDTH(285/3));
            make.top.equalTo(self).offset(BILIHEIGHT(1)+i/3*BILIHEIGHT(35));
            make.size.equalTo(CGSizeMake(BILIWIDTH(285/3), BILIHEIGHT(35)));
        }];
    }
    
}
-(void)buttonClick:(UIButton *)button
{
    if (button==self.permissionButton) {
        button.selected=!button.selected;
        if (!button.selected) {
            for (NSInteger i=0; i<5; i++) {
                UIButton *button=(UIButton *)[self viewWithTag:100+i];
                button.selected=NO;
            }
        }
    }else{
        if (self.permissionButton.selected) {
            button.selected=!button.selected;
        }
    }
}

-(void)getArray:(NSArray *)array
{
    [self.permissionButton setTitle:array[0] forState:UIControlStateNormal];
    
    for (NSInteger i=0; i<5; i++) {
        UIButton *button=(UIButton *)[self viewWithTag:100+i];
        if (i<array.count-1) {
            button.hidden=NO;
            [button setTitle:array[i+1] forState:UIControlStateNormal];
        }else{
            button.hidden=YES;
        }
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
